
package br.com.gtacomputadores.control.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;


@Entity
@Table(name = "conta_bancaria")
public class Conta implements Serializable {

    @Id
    @GeneratedValue
    @Column(name = "cod_conta")
    private Integer conta;

    @ManyToOne
    @OnDelete(action = OnDeleteAction.CASCADE)
    @JoinColumn(name = "cod_usuario", nullable = false)
    private Usuario usuario;

    @Column(name = "des_conta")
    private String descricao;

    @Column(name = "dat_cadastro", nullable = false, updatable = false)
    private Date dataCadastro;

    @Column(name = "saldo_inicial")
    private float saldoInicial;

    @Column(name = "favorita")
    private boolean favorita;

    public Integer getConta() {
        return conta;
    }

    public void setConta(Integer conta) {
        this.conta = conta;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public Date getDataCadastro() {
        return dataCadastro;
    }

    public void setDataCadastro(Date dataCadastro) {
        this.dataCadastro = dataCadastro;
    }

    public float getSaldoInicial() {
        return saldoInicial;
    }

    public void setSaldoInicial(float saldoInicial) {
        this.saldoInicial = saldoInicial;
    }

    public boolean isFavorita() {
        return favorita;
    }

    public void setFavorita(boolean favorita) {
        this.favorita = favorita;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((conta == null) ? 0 : conta.hashCode());
        result = prime * result + ((dataCadastro == null) ? 0 : dataCadastro.hashCode());
        result = prime * result + ((descricao == null) ? 0 : descricao.hashCode());
        result = prime * result + (favorita ? 1231 : 1237);
        result = prime * result + ((usuario == null) ? 0 : usuario.hashCode());
        result = prime * result + Float.floatToIntBits(saldoInicial);
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Conta other = (Conta) obj;
        if (conta == null) {
            if (other.conta != null) {
                return false;
            }
        } else if (!conta.equals(other.conta)) {
            return false;
        }
        if (dataCadastro == null) {
            if (other.dataCadastro != null) {
                return false;
            }
        } else if (!dataCadastro.equals(other.dataCadastro)) {
            return false;
        }
        if (descricao == null) {
            if (other.descricao != null) {
                return false;
            }
        } else if (!descricao.equals(other.descricao)) {
            return false;
        }
        if (favorita != other.favorita) {
            return false;
        }
        if (usuario == null) {
            if (other.usuario != null) {
                return false;
            }
        } else if (!usuario.equals(other.usuario)) {
            return false;
        }
        if (Float.floatToIntBits(saldoInicial) != Float.floatToIntBits(other.saldoInicial)) {
            return false;
        }
        return true;
    }

}
